package com.neuedu.javase.io;

import java.io.*;

/***
 * 项目名称:  MyJavaSE 
 * 包：  com.neuedu.javase.io 
 * date:   2025/11/6   8:51  
 * 描述:  
 *  @author : 张金山
 *  作者博客:   https://blog.fulfill.com.cn
 */
public class CompareByteOrChar {


    public static void main(String[] args) {

        String  fileName = "D:\\upload\\introduce.txt";

        // readByte(fileName);
        readChar(fileName);

    }

    private static void readChar(String fileName) {
        Reader reader = null;
        try {
            reader = new FileReader(fileName);
            // byte b1 = (byte) reader.read();
            // byte b2 = (byte) reader.read();

            System.out.println((char)reader.read());
            System.out.println((char)reader.read());


        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    private static void readByte(String fileName) {
        InputStream is = null;
        try {
            is = new FileInputStream(fileName);
            byte b1 = (byte) is.read();
            byte b2 = (byte) is.read();

            System.out.println((char)b1);
            System.out.println((char)b2);


        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
